home *** CD-ROM | disk | FTP | other *** search
- ;File: FkeyTemp.Asm
- ;-------------------------------------------------
- ;An Fkey sampler Fkey
- ;By John Holder 2/8/87
- ;Revised 3/29/88
- ;-------------------------------------------------
- Include Traps.D
- Include Toolequ.D
- Include Sysequ.D
-
- ;-------------------------------------------------
- ;Macros to save & restore the registers
- ;-------------------------------------------------
- MACRO SaveRegs =
- movem.l A0-A4/D0-D7,-(SP)
- |
-
- MACRO RestoreRegs =
- movem.l (SP)+,A0-A4/D0-D7
- |
-
- ;-------------------------------------------------
- ;All equates go here
- ;-------------------------------------------------
- ;these are offsets into the global storage.
- ;(a non-relocatable block we created pointed to by A4)
- ;-------------------------------------------------
- sfReply equ 0 ;sfreply record
- GetVRef equ 6
- GetVers equ 8
- GFileName equ 10
- IOParamBlk equ 76 ;IOparamblock (80 bytes)
- WindPtr equ 156 ;for our background ;window
- EventBlk equ 160 ;Event Block
- what equ 160 ;Event number
- message equ 162 ;Additional information
- when equ 166 ;Time event was posted
- where equ 170 ;Mouse coordinates
- modify equ 174 ;State of keys and button
- wWindow equ 176 ;Window pointer
- Menu1Hndl equ 180 ;handle to our Apple menu
- Menu2Hndl equ 184 ;handle to our File menu
- oldMenuBar equ 188 ;handle to applications ;menu
- TheWindow equ 192 ;for _FindWindow
-
- ;event masks for _GetOSEvent
- mDownMask equ 2
- keyDownMask equ 8
-
- ;Menu equates
- AppleMenu equ 1 ;Apple Menu
- AboutItem equ 1
- FileMenu equ 2 ;File Menu
- OpenFkeyItem equ 1
- QuitItem equ 3
-
- ;------------------------------------------------
- ;All FKEY's must have this FKEY resource header!
- ;-------------------------------------------------
- bra.s StartIt ;branch over header
- dc 0 ;flags (not used)
- dc.b 'FKEY' ;resource type
- dc 9 ;Resource ID #
- dc 0 ;version # (not used)
- ;-------------------------------------------------
- StartIt
- SaveRegs ;save regs MACRO
- subq #4,SP
- move.l SP,-(SP)
- _GetPort ;save Port for later
- _InitCursor ;standard arrow cursor
-
- ;does application have a menu??? if not, then quit!
- move.l MenuList,D0
- beq NoMenuJump ;no menu, beep & quit!
-
- move.l #200,D0 ;200 bytes of storage
- _NewPtr,CLEAR ;for our globals
- move.l A0,A4 ;pointer in A4
- cmp.l #0,A4
- bne.s StorageOk ;if not zero, ptr is ok!
-
- NoMenuJump
- bsr Mem_Error ;otherwise beep
- bra No_Mem ;and quit
-
- StorageOk
- bsr SetUpMenus ;set up our menus
- bsr SetUpWindow ;set up background ;window
- ;-------------------------------------------------
- MainLoop ;standard event loop
- _SystemTask
- clr -(SP)
- move #$0FFF,-(SP) ;event mask
- pea EventBlk(A4) ;Place to return results
- _GetNextEvent ;Look for an event
- move (SP)+,D2
- beq MainLoop ;zero if we shouldn't
- move What(A4),D0 ;respond
- add D0,D0
- move EventTable(D0),D0
- jmp EventTable(D0) ;jump to appropriate ;routine
-
- EventTable
- dc MainLoop-EventTable ;null event
- dc MouseDown-EventTable ;mouse down
- dc MainLoop-EventTable ;mouse up
- dc KeyDown-EventTable ;key down
- dc MainLoop-EventTable ;key up
- dc KeyDown-EventTable ;auto key
- dc UpDateJump-EventTable ;update event
- dc MainLoop-EventTable ;disk event
- dc MainLoop-EventTable ;activate event
- dc MainLoop-EventTable ;abort
- dc MainLoop-EventTable ;network event
- dc MainLoop-EventTable ;I/O driver event
-
- ;-------------------------------------------------
- SetUpWindow
- clr.l -(SP) ;for returned pointer
- clr.l -(SP) ;let Mac make storage
- pea WindowRect ;windows rectangle
- clr.l -(SP) ;no title
- move.b #1,-(SP) ;it is visible
- move #plainDBox,-(SP) ;Type of window
- move.l #-1,-(SP) ;in front
- move.b #0,-(SP) ;no close box
- clr.l -(SP) ;refcon zero
- _NewWindow ;make window!
- move.l (SP),WindPtr(a4) ;pointer into global
- _SetPort ;set as the port
- rts
-
- ;-------------------------------------------------
- SetUpMenus
- clr.l -(SP) ;get applications menu
- _GetMenuBar ;bar handle for later
- move.l (SP)+,oldMenuBar(A4) ;restoration!
- _ClearMenuBar ;clear Apps menu bar
-
- ;make all of our menus
- ;the apple menu
- clr.l -(SP)
- move #1,-(SP)
- pea AppleSymbol
- _NewMenu
- move.l (SP)+,Menu1Hndl(A4)
- move.l Menu1Hndl(A4),-(sp)
- pea 'About Fkey Sampler...'
- _AppendMenu
- move.l Menu1Hndl(A4),-(sp)
- move #2,-(SP)
- _InsertMenu
- ;the File menu
- clr.l -(SP)
- move #2,-(SP)
- pea 'File'
- _NewMenu
- move.l (SP)+,Menu2Hndl(A4)
- move.l Menu2Hndl(A4),-(sp)
- pea 'Open FKEY/F'
- _AppendMenu
- move.l Menu2Hndl(A4),-(sp)
- pea '(-'
- _AppendMenu
- move.l Menu2Hndl(A4),-(sp)
- pea 'Quit/Q'
- _AppendMenu
- move.l Menu2Hndl(A4),-(sp)
- clr -(SP)
- _InsertMenu
- _DrawMenuBar ;draw the new menu bar
- rts
-
- UpDateJump
- bsr UpDateWindow
- bra MainLoop
-
- ;-------------------------------------------------
- ;This routine keeps our background window (The DeskTop!)
- ;the same pattern as the current standard desktop!
- ;-------------------------------------------------
- UpDateWindow
- move.l WindPtr(A4),-(SP) ;our background ;window
- _BeginUpdate ;is kept in WindPtr(A4)
- move.l WindPtr(A4),-(SP)
- _SetPort
- pea PaintRect ;the rectangle to paint
- pea DeskPattern ;global var, contains
- _FillRect ;pattern used for desktop
- move.l WindPtr(A4),-(SP)
- _EndUpdate
- rts
-
- ;-------------------------------------------------
- ;A key down event occured, check if the command key was
- ;down, if not, get the next event!
- ;-------------------------------------------------
- KeyDown
- move Modify(A4),D1
- btst #8,D1 ;check command key bit
- beq MainLoop ;zero if command key
- ;is not down!
- clr.l -(sp)
- move message+2(A4),-(sp) ;put char onto stack
- _MenuKey ; for _MenuKey
- move.l (sp)+,D4 ;put result in D4
- beq MainLoop ;if zero, no menu ;equivalent
- bra WhatMenu
-
- ;-------------------------------------------------
- ;A mousedown event occured, we only check if its in a menu, if
- ;not then get the next event!
- ;-------------------------------------------------
- MouseDown
- clr -(SP) ;word result
- move.l where(A4),-(SP) ;where field of ;event record
- pea TheWindow(A4) ;returns the window ;pntr the
- _FindWindow ;mouse was clicked in,
- move (SP)+,D0 ;if it was in one.
-
- add D0,D0
- move WindowTable(D0),D0
- jmp WindowTable(D0) ;jump to appropriate ;routine
-
- ;We only use InMenu event!
- WindowTable
- dc MainLoop-WindowTable ;In Desk
- dc InMenu-WindowTable ;In Menu Bar
- dc MainLoop-WindowTable ;In System Window
- dc MainLoop-WindowTable ;in Content
- dc MainLoop-WindowTable ;in drag
- dc MainLoop-WindowTable ;in grow
- dc MainLoop-WindowTable ;in go away
-
- ;-------------------------------------------------
- ;The mouse was clicked in the menu bar.
- ;-------------------------------------------------
- InMenu
- clr.l -(SP)
- move.l where(A4),-(SP)
- _MenuSelect
- move.l (SP)+,D4
- beq MainLoop ;zero if no item selected
-
- ;jump to here after command key down event
- WhatMenu
- move.l D4,D6 ;D6 will now have the
- swap D4 ; item # D4 will have ;menu #
- WhichMenuWasIt
- cmp #AppleMenu,D4 ;is it in the apple menu?
- beq InAppleMenu ;if so, go see which ;item!
- cmp #FileMenu,D4 ;is it in the File menu?
- beq InFileMenu
- bra MainLoop ;where else could it be!
-
- InAppleMenu ;in the "Apple" menu
- cmp #AboutItem,D6
- beq DoAbout ;its in the About... Item!
- bra MainLoop
-
- InFileMenu ;in the "File" menu
- cmp #OpenFkeyItem,D6 ;in the OpenFkey Item?
- beq Open_Fkey ;if so go open it!
- cmp #QuitItem,D6 ;Quit item?
- beq QuitRoutine ;if so go quit
- bra MainLoop
-
- ;-------------------------------------------------
- ;Show the "About Fkey Sampler..." window
- ;-------------------------------------------------
- DoAbout
- saveregs ;save the registers
-
- clr.l -(SP)
- clr.l -(SP)
- pea AboutRect
- move.l #0,-(SP)
- move.b #1,-(SP)
- move #1,-(SP)
- move.l #-1,-(SP)
- move.b #0,-(SP)
- clr.l -(SP)
- _NewWindow ;make a window
- move.l (SP),A2 ;put pointer into A2
- _SetPort ;make it the port
-
- move #Monaco,-(SP) ;Use the Monaco Font
- _TextFont
- move #9,-(SP) ;make it 9 point (size)
- _TextSize
-
- pea MyTextBegin ;address of "About" Text
-
- ;calculate how many chars in text for TextBox
- move.l #MyTextEnd-MyTextBegin,-(SP)
- pea TextRect ;rectangle for text
- move #1,-(SP) ;center justification
- _TextBox
- bsr Wait_For_Event ;wait for button/key down
- move.l A2,-(SP)
- _DisposWindow ;get rid of the window
- bsr UnHiliteIt ;go unhilight the menu!
- move.l WindPtr(A4),-(sp)
- _SetPort ;reset our old port
- restoreregs ;restore registers
- bra MainLoop ;go get another event
-
- ;-------------------------------------------------
- ;Wait for mouse or key down event
- ;-------------------------------------------------
- Wait_For_Event
- link A6,#-evtBlkSize ;link, event block size
- WaitLoop
- lea -evtBlkSize(A6),A0 ;ptr to event block in A0
- moveq #mDownMask!KeyDownMask,D0 ;Event masks in D0
- _GetOSEvent
- beq Clicked ;if zero, time to leave!
- bra WaitLoop ;loop until event
- Clicked ;mouse or key clicked!
- unlk A6 ;unlink A6
- rts
-
- ;-------------------------------------------------
- ;Quitting, dispose of all our storage and menus and return to
- ;the application that the Fkey was called from!
- ;-------------------------------------------------
- QuitRoutine
- move.l WindPtr(A4),-(SP) ;dump background
- _DisposWindow ;window
- move.l Menu1Hndl(A4),-(SP) ;dump our #1
- _DisposMenu ;menu
- move.l Menu2Hndl(A4),-(SP) ;dump our #2
- _DisposMenu ;menu
- _ClearMenuBar ;clear the menu
- move.l oldMenuBar(A4),-(SP)
- _SetMenuBar ;restore apps menu bar!
- move.l oldMenuBar(A4),A0 ;dump copy of
- _DisposHandle ;apps menu handle!
- _DrawMenuBar ;draw it
- move.l A4,A0
- _DisposPtr ;dump our global ;storage
-
- No_Mem
- move.l #$0000FFFF,D0 ;flush all events
- _FlushEvents
- _SetPort ;set original port!
- restoreregs ;restore the registers
- rts ;return to the application!
-
- ;-------------------------------------------------
- ;Couldn't allocate space for our global storage area
- ;just beep & quit!
- ;-------------------------------------------------
- Mem_Error
- move #10,-(SP)
- _SysBeep
- rts
-
- ;-------------------------------------------------
- ;Unhilight menu bar after mouse down in a menu item
- ;-------------------------------------------------
- UnHiliteIt
- move #0,-(SP)
- _HiliteMenu
- rts
-
- ;-------------------------------------------------
- ;Get a file of type "FKEY", open its resource fork, and
- ;execute the Fkey (if there is one) contained in it!
- ;-------------------------------------------------
- Open_Fkey
- saveregs ;save registers
- move #82,-(SP) ;coordinates for GetFile
- move #100,-(SP) ;dialog box
- clr.l -(SP) ;prompt
- clr.l -(SP) ;File Filter Proc Pointer
- move #1,-(SP) ;number of file types
- pea TypeList ;our type list
- clr.l -(SP) ;Dialog Hook Proc Pointer
- pea sfReply(A4) ;sfreply record
- move #2,-(SP) ;#2 for SFGetFile
- _Pack3 ;Call the Get File Pack
- cmp.b #0,sfReply(A4)
- beq Cancel ;if user hit cancel, quit!
-
- bsr UpDateWindow ;update window before
- ;opening the Fkey
- lea IOParamBlk(A4),A2 ;the IO param block
- clr.l 12(A2) ;zero "ioCompletion"
- lea GFileName(A4),A0 ;put a pointer to the files
- move.l A0,18(A2) ;name into "ioNamePtr"
- move GetVRef(A4),22(A2) ;"ioVRefNum"
- move.l A2,A0 ;put param block ptr in A0
- _SetVol ;set as current volume
-
- clr -(SP) ;space for refnum
- pea GFileName(A4) ;name of res file to open
- _OpenResFile ;Open that resource file
- move (SP)+,D7 ;put result in D7
- cmp #-1,D7 ;will be -1 if any
- ;errors!
- beq Cancel ;if error go to cancel
-
- ;this stops resources from being loaded with GetIndResource,
- ;GetResource or GetNamedResource
- move.w #0,-(sp)
- _SetResLoad
-
- clr.l -(sp)
- move.l #'FKEY',-(sp)
- move #1,-(sp)
- _GetIndResource ;get first FKEY resource
- move.l (sp)+,A3 ;handle into A3
-
- ;Turns Automatic resource loading back on!
- move.b #1,-(sp)
- _SetResLoad
-
- clr.l -(sp)
- move.l A3,-(sp)
- _SizeRsrc
- move.l (sp)+,D2 ;how big is the resource?
- cmp.l #-1,D2 ;-1 = no resource
- beq NotEnoughMem ;no resource error so quit
-
- ;do we have enough memory to load the FKEY
- move.l D2,D0
- _NewHandle
- move.l A0,A1
- cmp.l #0,A1 ;was zero returned?
- beq NotEnoughMem ;not enough room, so quit!
- _DisposHandle ;otherwise dispose the new
- ;handle, and go on..
- move.l A3,-(sp)
- _LoadResource ;Load resource into memory!
- clr -(sp)
- move.l A3,-(SP)
- _HomeResFile ;what resource file
- move (sp)+,D2 ;is this resource from?
-
- cmp D2,D7 ;is it from new file?
- beq YepItsFromNewFile ;yep!
- bra NotEnoughMem ;if not, close the res
- ;file and quit!
- YepItsFromNewFile
- move.l A3,A0
- _Hlock ;Lock it before jumping to it
- move.l (A3),A2 ;put pointer to FKEY in A2
- SaveRegs ;save the regs
- jsr (A2) ;Run the Fkey!!
- RestoreRegs ;restore the regs
- move.l A3,A0
- _HUnlock ;UnLock FKEY handle
- bsr CloseIt ;go close res file
-
- Cancel
- restoreregs ;restore the regs
- bsr UnHiliteIt ;unhilight the menu
- bra MainLoop ;get the next event
-
-
- NotEnoughMem
- bsr CloseIt
- bra Cancel
-
- CloseIt
- move D7,-(SP)
- _CloseResFile ;Close the res file
- rts
-
- ;-------------------------------------------------
- ;All constants go here
- ;-------------------------------------------------
- ;rect of background (desktop) window
- ;make it giant to cover entire background!
- WindowRect dc 0,0,4000,4000
-
- PaintRect dc 0,0,4000,4000
-
- TypeList dc.b 'FKEY'
- .ALIGN 2
-
- ;rect of "About..." window
- AboutRect dc 130,100,190,412
-
- ;rect text will be displayed in for _TextBox
- TextRect dc 10,10,90,302
-
- AppleSymbol dc.b 1,$14 ;apple symbol for menu #1
- .ALIGN 2
-
- MyTextBegin dc.b 'Fkey Sampler 1.0',$0D,$0D
- dc.b 'Written by John Holder'
- .ALIGN 2
- MyTextEnd
-
- END